package com.bpc.cs.dto;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.bpc.cs.constant.DBConstant;

/**
 * @author   phan_tp
 * @datetime Nov 30, 2012 : 2:16:59 PM
 */

@Entity
@Table (name = DBConstant.TBL_SCORING_RULE)
public class RuleDTO {

	@Id
	@SequenceGenerator(name = "generator_rule", sequenceName = "rule_id_seq",
			   		   catalog = "CREDIT_SCORING", schema = "SCREDIT_SCORING", allocationSize = 1)
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator_rule")
	@Column (name = DBConstant.COL_SR_ID, unique = true, nullable = false)
	private int ruleID;

	@Column (name = DBConstant.COL_SR_WEIGHT, unique = false, nullable = false)
	private float weight;

	@ManyToOne
	@JoinColumn (name = DBConstant.COL_SR_SS_ID)
	private SchemeDTO schemeDTO;

	@ManyToOne
	@JoinColumn (name = DBConstant.COL_SR_SF_ID)
	private FactorDTO factorDTO;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "ruleDTO")
	@Cascade(CascadeType.ALL)
	@Fetch(FetchMode.SELECT)
	private Set<FactorChoiceDTO> factorChoiceTO;

	/**
	 * Default contructor
	 */
	public RuleDTO() {}

	/**
	 * Contructor init ruleDTO and init som property
	 * @param SchemeDTO schemeDTO
	 * @param FactorDTO factorDTO
	 * @param int weight
	 */
	public RuleDTO(SchemeDTO schemeDTO, FactorDTO factorDTO, float weight) {
		this.factorDTO = factorDTO;
		this.schemeDTO = schemeDTO;
		this.weight = weight;
	}

	/**
	 * @return the ruleID
	 */
	public int getRuleID() {
		return ruleID;
	}

	/**
	 * @param ruleID the ruleID to set
	 */
	public void setRuleID(int ruleID) {
		this.ruleID = ruleID;
	}

	/**
	 * @return the schemeID
	 */
	public SchemeDTO getSchemeDTO() {
		return schemeDTO;
	}

	/**
	 * @param schemeDTO  the schemeDTO  to set
	 */
	public void setSchemeDTO(SchemeDTO schemeDTO) {
		this.schemeDTO = schemeDTO ;
	}

	/**
	 * @return the weight
	 */
	public float getWeight() {
		return weight;
	}

	/**
	 * @param weight the weight to set
	 */
	public void setWeight(float weight) {
		this.weight = weight;
	}

	/**
	 * @return the factorID
	 */
	public FactorDTO getFactorDTO() {
		return factorDTO;
	}

	/**
	 * @param factorID the factorID to set
	 */
	public void setFactorDTO(FactorDTO factorDTO) {
		this.factorDTO = factorDTO;
	}

	/**
	 * @return the factorChoiceTO
	 */
	public Set<FactorChoiceDTO> getFactorChoiceTO() {
		return factorChoiceTO;
	}

	/**
	 * @param factorChoiceTO the factorChoiceTO to set
	 */
	public void setFactorChoiceTO(Set<FactorChoiceDTO> factorChoiceTO) {
		this.factorChoiceTO = factorChoiceTO;
	}

}
